package com.li.youhappygo.controller;

import com.github.xiaoymin.knife4j.annotations.DynamicParameter;
import com.github.xiaoymin.knife4j.annotations.DynamicResponseParameters;
import com.li.youhappygo.model.dto.LoginDto;
import com.li.youhappygo.model.entity.system.SysUser;
import com.li.youhappygo.model.vo.common.Result;
import com.li.youhappygo.model.vo.common.ResultCode;
import com.li.youhappygo.model.vo.system.LoginVo;
import com.li.youhappygo.service.SysService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponses;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
//@Slf4j
@RequestMapping("/admin/system")
@Tag(name = "系统管理", description = "系统管理")
public class SysController {
    @Autowired
    SysService sysService;
    @PostMapping("login")
    @Operation(description = "登录",summary = "登录",
            responses ={
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "201", description = "操作失败"),
                    @ApiResponse(responseCode = "208", description = "用户未登录"),
                    @ApiResponse(responseCode = "9999", description = "系统异常，请稍后重试"),
                    @ApiResponse(responseCode = "204", description = "数据异常"),
                    @ApiResponse(responseCode = "219", description = "库存不足"),
    })
    public Result<LoginVo> login(@Parameter(description = "登录信息",required = true) @RequestBody LoginDto loginDto){
        LoginVo loginVo = sysService.login(loginDto);
        return Result.build(loginVo, ResultCode.SUCCESS);
    }
    @GetMapping("/loginOut")
    @Operation(description = "登出账号",summary = "登出")
    public Result loginOut(String token){
        sysService.loginOut(token);
        return Result.build(null,ResultCode.SUCCESS );
    }
    @GetMapping("/getSysUserInfo")
    @Operation(description = "获取用户信息",summary = "获取用户信息")
    public Result<SysUser> getUserInfo(@RequestHeader(value = "token") String token){
        SysUser sysUser = sysService.getUserInfo(token);
        return Result.build(sysUser,ResultCode.SUCCESS );
    }


}

